//
//  UINavigationBar+customBar.m
//  高仿暴走斗图
//
//  Created by key on 16/3/21.
//  Copyright © 2016年 huangsongyao. All rights reserved.
//

#import "UINavigationBar+customBar.h"

@implementation UINavigationBar (customBar)


#pragma mark - Bar Background Color

- (void)customBarTintColor:(UIColor *)color {
    
    if ([self respondsToSelector:@selector(setBarTintColor:)]) {
        
#if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_7_0
        
        [self setBarTintColor:[UIColor whiteColor]];
#else
        [self setTintColor:[UIColor whiteColor]];
#endif
    }
}

#pragma mark - Bar Bottom Line Color

- (void)clearBarBottomLineWithTintColor:(UIColor *)tintColor {
    
    [self customBarBottomLineOfColor:CLEAR_COLOR withTintColor:tintColor];
}

- (void)customBarBottomLineOfColor:(UIColor *)color withTintColor:(UIColor *)tintColor {
    
    if ([self respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) {
        
        UIImage *img = [[HSYColorHelper shareInstance] canvasImageWithColor:tintColor];
        [self setBackgroundImage:img forBarMetrics:UIBarMetricsDefault];
        
    } else {
        [self setNeedsDisplay];
    }
    
    [self setShadowImage:[[HSYColorHelper shareInstance] canvasImageWithColor:CLEAR_COLOR]];
    
    CGFloat height = 1.0f;
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, self.viewHeight - height, self.viewWidth, height)];
    [lineView setBackgroundColor:color];//navigationBar底部的线
    [self addSubview:lineView];
}


#pragma mark - Move Bar To Top

- (void)setTanslationY:(CGFloat)translationY {
    
    self.transform = CGAffineTransformMakeTranslation(0, translationY);
}

- (void)setTanslationYMoveUpFromAlpha:(CGFloat)alpha {
    
    [[self subviews] enumerateObjectsUsingBlock:^(UIView *obj, NSUInteger idx, BOOL *stop) {
        if ([obj isKindOfClass:NSClassFromString(@"UINavigationItemView")]) {
            obj.alpha = alpha;
            *stop = YES;
        }
    }];
}

@end
